<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pages/common/common.jsp"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%@ include file="/pages/common/common.jsp"%>
<title>${rptInfo.rptName}</title>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/scripts/jquery-easyUI/1.5.2/themes/metro/easyui.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/scripts/jquery-easyUI/1.5.2/themes/icon.css" />
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery-easyUI/1.5.2/jquery.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery-easyUI/1.5.2/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery-easyUI/1.5.2/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jquery-easyUI/1.5.2/datagrid-cellediting.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/page/showRptInfo.js"></script>
    <script type="application/javascript">
        var basePath = "${pageContext.request.contextPath}";
    </script>
    <style type="text/css">
        .tb-ul {
            overflow:hidden;
            width:100%;
            margin:0 auto;
            text-align:center;
        }
        .tb-li {
            list-style:none;
            text-align: left;
            float:left;
            width:25%;
            padding-top: 5px;
        }
    </style>
</head>

<body onload="onLoadFun();">

    <div id="layout" class="easyui-layout" style="width:700px;height:350px;">
        <div data-options="region:'north'" style="height:50px">
            <!--动态生成查询条件-->
            <div id="tb" style="height:auto">
                <input type="hidden" id="rptId" name="rptId" value="${rptId}">
                <input type="hidden" id="conditionCol" name="conditionCol" value="${conditionColumns}">
                <input type="hidden" id="initCondition" name="initCondition" value="${initConditions}">
                <input type="hidden" id="rptToken" name="rptToken" value="${rptInfo.rptToken}">
                <c:choose>
                <c:when test="${empty rptInfo.conditionColumns}">
                    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="showRptInfo.query();">查询</a>
                    <c:if test="${rptInfo.needImport == '1'}">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-excel',plain:true" onclick="showRptInfo.downLoadExcel()">导出Excel</a>
                    </c:if>
                </c:when>
                <c:otherwise>
                <div style="padding:2px 2px;margin: 2px;">
                    <ul class="tb-ul">
                            <c:set var="count" value="0"/>
                        <c:forEach items="${rptInfo.conditionColumns}" var="condition" varStatus="status">
                        <c:if test="${count % 4 == 0}">
                            <%--<div style="padding-top:5px;"></div>--%>
                        <ul class="tb-ul">
                            </c:if>
                            <c:choose>
                            <c:when test="${condition.conditionType == '1'}">  <!-- 查询类型-输入框-->
                            <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                <c:if test="${condition.isVisibility != '0'}">
                                    <c:set value="${count + 1}" var="count" />
                                </c:if>
                                <label>${condition.name}:</label>
                                <input class="easyui-textbox" id="${condition.aliasField}" value="${condition.defaultValue}" style="width:130px;height:25px">
                                <c:if test="${condition.dynamicFormat == 'formatType'}">
                                    <span name="formatType">${condition.countType}</span>
                                </c:if>
                                <span>${condition.unit}</span>
                                <c:if test="${condition.isNeed == '1'}">
                                    <span><font color='red'>*</font></span>
                                </c:if>
                            </li>
                            </c:when>
                            <c:when test="${condition.conditionType == '2'}">  <!-- 查询类型-下拉框 -->
                            <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                <c:if test="${condition.isVisibility != '0'}">
                                    <c:set value="${count + 1}" var="count" />
                                </c:if>
                                <label>${condition.name}:</label>
                                <c:choose>
                                    <c:when test="${condition.aliasField == 'formatType'}"> <!--动态格式化数字-->
                                        <select class="easyui-combobox" style="height: 27px;width:130px;" <c:if test="${fn:length(condition.optionValue) lt 9 }">panelHeight="auto"</c:if> id="${condition.aliasField}" name="${condition.aliasField}" onchange="showRptInfo.query()">
                                            <c:forEach items="${condition.optionValue}" var="option">
                                                <option value="${option.key}"<c:if test="${option.key == condition.defaultValue}"> selected</c:if>>${option.value}</option>
                                            </c:forEach>
                                        </select>
                                    </c:when>
                                    <c:when test="${condition.aliasField == 'dateType'}"> <!--动态格式化日期-->
                                        <select class="ui-select" style="height: 27px;width:100px;padding-left: 2px;" id="${condition.aliasField}" name="${condition.aliasField}" onchange="showRptInfo.foratterDate('${condition.cascadeDate}','${condition.cascadeCondition}')">
                                            <c:forEach items="${condition.optionValue}" var="option">
                                                <option value="${option.key}"<c:if test="${option.key == condition.defaultValue}"> selected</c:if>>${option.value}</option>
                                            </c:forEach>
                                        </select>
                                    </c:when>
                                    <c:otherwise>
                                        <select class="easyui-combobox" style="height: 27px;width:130px;" <c:if test="${fn:length(condition.optionValue) lt 9 }">panelHeight="auto"</c:if> id="${condition.aliasField}" name="${condition.aliasField}">
                                            <c:forEach items="${condition.optionValue}" var="option">
                                                <option value="${option.key}"<c:if test="${option.key == condition.defaultValue}"> selected</c:if>>${option.value}</option>
                                            </c:forEach>
                                        </select>
                                    </c:otherwise>
                                </c:choose>
                                    <%--<select class="easyui-combobox" id="${condition.aliasField}" name="${condition.aliasField}" style="width:130px;" <c:if test="${fn:length(condition.optionValue) lt 9 }">panelHeight="auto"</c:if>
                                            <c:if test="${condition.aliasField == 'formatType'}"> onchange="showRptInfo.query()"</c:if>>
                                        <c:forEach items="${condition.optionValue}" var="option">
                                            <option value="${option.key}">${option.value}</option>
                                        </c:forEach>
                                    </select>--%>
                                <c:if test="${condition.dynamicFormat == 'formatType'}">
                                    <span name="formatType">${condition.countType}</span>
                                </c:if>
                                <span>${condition.unit}</span>
                                <c:if test="${condition.isNeed == '1'}">
                                    <span><font color='red'>*</font></span>
                                </c:if>
                            </li>
                            </c:when>
                            <c:when test="${condition.conditionType == '3'}">  <!-- 查询类型 - 日期 -->
                            <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                <c:if test="${condition.isVisibility != '0'}">
                                    <c:set value="${count + 1}" var="count" />
                                </c:if>
                                <label>${condition.name}:</label>
                                <input id="${condition.aliasField}" name="${condition.aliasField}" value="${condition.defaultValue}" style="margin-top: 1px;width:150px;" onFocus="WdatePicker({onpicked:function() {},dateFmt:'${condition.formatter}'})" type="text" class="Wdate">
                                <c:if test="${condition.isNeed == '1'}">
                                    <span><font color='red'>*</font></span>
                                </c:if>
                            </li>
                            </c:when>
                            <c:when test="${condition.conditionType == '4'}">  <!--查询类型 - 日期区间-->
                            <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                <c:if test="${condition.isVisibility != '0'}">
                                    <c:set value="${count + 1}" var="count" />
                                </c:if>
                                <label>起始时间: </label>
                                <input id="${condition.aliasField}_start" name="${condition.aliasField}_start" value="${condition.defaultValue}" style="margin-top: 1px;width:150px;" onFocus="WdatePicker({onpicked:function() {},dateFmt:'${condition.formatter}'})" type="text" class="Wdate">
                                <c:if test="${condition.isNeed == '1'}">
                                    <span><font color='red'>*</font></span>
                                </c:if>
                            </li>
                            <c:if test="${count % 4 == 0}">
                                <%--<div style="padding-top:5px;"></div>--%>
                            <ul class="tb-ul">
                                </c:if>
                                <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                    <c:if test="${condition.isVisibility != '0'}">
                                        <c:set value="${count + 1}" var="count" />
                                    </c:if>
                                    <label>结束时间: </label>
                                    <input id="${condition.aliasField}_end" name="${condition.aliasField}_end" value="${condition.defaultValueEnd}" style="margin-top: 1px;width:150px;" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'${condition.aliasField}_start\')}',onpicked:function() {},dateFmt:'${condition.formatter}'})" type="text" class="Wdate">
                                    <c:if test="${condition.isNeed == '1'}">
                                        <span><font color='red'>*</font></span>
                                    </c:if>
                                </li>
                                </c:when>
                                <c:when test="${condition.conditionType == '5'}">  <!--查询类型 - 树-->
                                    <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                        <c:if test="${condition.isVisibility != '0'}">
                                            <c:set value="${count + 1}" var="count" />
                                        </c:if>
                                        <label>${condition.name}:</label>
                                        <input type="text" class="textinput" name="${condition.aliasField}" id="${condition.aliasField}Id" value="${condition.defaultName}" style="width:130px;height:24px;font-size:12px;" onclick="selectMyOrgTree('${rptId}','${condition.aliasField}','${condition.treeDim.rightParam}','${condition.treeDim.parentRightParam}');">
                                        <input type="hidden" name="${condition.aliasField}s" id="hid_${condition.aliasField}" value="'${condition.defaultValue}'">
                                        <c:if test="${condition.dynamicFormat == 'formatType'}">
                                            <span name="formatType">${condition.countType}</span>
                                        </c:if>
                                        <span>${condition.unit}</span>
                                        <c:if test="${condition.isNeed == '1'}">
                                            <span><font color='red'>*</font></span>
                                        </c:if>
                                    </li>
                                </c:when>
                                <c:when test="${condition.conditionType == '6'}">  <!-- 查询类型-值区间-->
                                    <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                        <c:if test="${condition.isVisibility != '0'}">
                                            <c:set value="${count + 1}" var="count" />
                                        </c:if>
                                        <label>${condition.name}:</label>
                                        <input class="easyui-textbox" id="${condition.aliasField}_start" value="${condition.defaultValue}" style="width:50px;height:25px">
                                        <c:if test="${condition.isNeed == '1'}">
                                            <span><font color='red'>*</font></span>
                                        </c:if>
                                        &nbsp;至&nbsp;
                                        <input class="easyui-textbox" id="${condition.aliasField}_end" value="${condition.defaultValueEnd}" style="width:50px;height:25px">
                                        <c:if test="${condition.dynamicFormat == 'formatType'}">
                                            <span name="formatType">${condition.countType}</span>
                                        </c:if>
                                        <span>${condition.unit}</span>
                                        <c:if test="${condition.isNeed == '1'}">
                                            <span><font color='red'>*</font></span>
                                        </c:if>
                                    </li>
                                </c:when>
                                <c:when test="${condition.conditionType == '7'}">  <!-- 查询类型-多选下拉框 -->
                                    <li class="tb-li" <c:if test="${condition.isVisibility == '0'}"> style="display: none;" </c:if>>
                                        <c:if test="${condition.isVisibility != '0'}">
                                            <c:set value="${count + 1}" var="count" />
                                        </c:if>
                                        <label>${condition.name}:</label>
                                        <select class="easyui-combobox" data-options="multiple:true,panelHeight:'auto'" id="${condition.aliasField}" name="${condition.aliasField}" style="width:130px;">
                                            <c:forEach items="${condition.optionValue}" var="option">
                                                <option value="${option.key}">${option.value}</option>
                                            </c:forEach>
                                        </select>
                                        <c:if test="${condition.dynamicFormat == 'formatType'}">
                                            <span name="formatType">${condition.countType}</span>
                                        </c:if>
                                        <span>${condition.unit}</span>
                                        <c:if test="${condition.isNeed == '1'}">
                                            <span><font color='red'>*</font></span>
                                        </c:if>
                                    </li>
                                </c:when>
                                </c:choose>
                                </c:forEach>
                                <c:if test="${count % 4 == 0}">
                                <ul class="tb-ul">
                                    </c:if>
                                    <li class="tb-li">
                                        <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="showRptInfo.query();">查询</a>
                                        <c:if test="${rptInfo.needImport == '1'}">
                                            <a href="#" class="easyui-linkbutton" iconCls="icon-excel" onclick="showRptInfo.downLoadExcel();">导出Excel</a>
                                        </c:if>
                                            <%--<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="openNewWin();">新页面查询</a>--%>
                                    </li>
                                    <c:if test="${count % 4 == 0}">
                                </ul>
                                </c:if>
                            </ul>
                            </c:otherwise>
                        </c:choose>
                </div>
        </div>
        <div data-options="region:'east',split:true,title:'East',collapsible:false" style="width:250px;">
        </div>
        <div data-options="region:'center',title:'Main Title',iconCls:'icon-ok'" style="padding:10px">
            <table id="dg" class="easyui-datagrid" title="${rptInfo.rptName}" data-options="singleSelect:true,toolbar:'#tb',collapsible:true,method:'POST',
							rownumbers: false" style="width:100%;height:100%;">
            </table>
        </div>
    </div>
    
    <script type="text/javascript">

		// 数据列
		var columns = "${columns}";
		// 冻结列
		var lockColumns = "${lockColumns}";
		// 报表是否分页
		var isPage = "${rptInfo.needPage}";
        // 外部系统传入参数
        var thirdParams = "${thirdParams}";
        // 报表初始化参数
        var initConditions = "${initConditions}";

        /**
         * 表格自适应屏幕大小
         */
        window.onresize = function(){
            setTimeout(onLoadFun,300);
        }

        function onLoadFun() {
            $('#dg').datagrid('resize',{
                height:($(window).height())
            });
        }

        $("#layout").layout('remove','east');

        //报表下钻
        function rptDrill(rptId, drillParam, conditionParam, drillLayout, value, row, index) {
            rptId = rptId + "encode";
            rptId = encode64(rptId);
            rptId = encode64(rptId);
            var newRptURL = basePath + "/rptTools/showRpt/showRptIndex";
            var reqParam = "";
            var params = new Array();
            var conditions = new Array();
            params = drillParam.split(",");
            for(i=0; i<params.length; i++) {
                var paramName = params[i];
                var paramValue = row[paramName];
                if(reqParam != '') {
                    reqParam = reqParam + "&" + paramName + "=" + paramValue
                } else {
                    reqParam = reqParam + paramName + "=" + paramValue
                }
            }

            conditions = conditionParam.split(",");
            for(i=0; i<conditions.length; i++) {
                var paramName = conditions[i];
                var paramValue = $("#" + paramName).val();
                if(reqParam != '') {
                    reqParam = reqParam + "&" + paramName + "=" + paramValue
                } else {
                    reqParam = reqParam + paramName + "=" + paramValue
                }
            }
            if(reqParam != "") {
                newRptURL = newRptURL + "?" + reqParam;
            }

            var token = $("#rptToken").val();
            return "<a style='color:#4697e5; text-decoration:none;' onclick='drillEvent(\"" + newRptURL + "\",\"" + token + "\",\"" + rptId + "\",\"" + drillLayout +"\")' href='javascript:void(0)'>" + value + "</a>";
            //return "<a style='color:#4697e5; text-decoration:none;' onclick='' href=\"" + newRptURL + "\" target='_blank'>" + value + "</a>";
        }

        function drillEvent(rptURL, token, rptId, drillLayout) {
            if(drillLayout == '0') {
                var form = $("<form>");//定义一个form表单
                form.attr("id", "drillForm");
                form.attr("style", "display:none");
                form.attr("target", "");
                form.attr("method", "post");
                form.attr("action", rptURL);

                var tokenInput = $("<input>");
                tokenInput.attr("type", "hidden");
                tokenInput.attr("name", "token");
                tokenInput.attr("id", "token");
                tokenInput.attr("value", token);
                form.append(tokenInput);

                var rptIdInput = $("<input>");
                rptIdInput.attr("type", "hidden");
                rptIdInput.attr("name", "rptId");
                rptIdInput.attr("id", "rptId");
                rptIdInput.attr("value", rptId);
                form.append(rptIdInput);

                $("body").append(form);//将表单放置在web中
                form.attr('target', '_blank');
                form.submit();//表单提交
            } else {
                var options = {
                    region: 'east'
                };
                options.width = 100;
                options.split = true;
                options.collapsible = false
                $('#layout').layout('add', options);
            }
        }

        function encode64(input) {
            input = input + "";
            var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "=";
            var output = "";
            var chr1, chr2, chr3 = "";
            var enc1, enc2, enc3, enc4 = "";
            var i = 0;
            do {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);
                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;
                if (isNaN(chr2)) {
                    enc3 = enc4 = 64;
                } else if (isNaN(chr3)) {
                    enc4 = 64;
                }
                output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)
                        + keyStr.charAt(enc3) + keyStr.charAt(enc4);
                chr1 = chr2 = chr3 = "";
                enc1 = enc2 = enc3 = enc4 = "";
            } while (i < input.length);
            return output;
        }

        //数字格式化
        function numberFormat(formatter, value, row, index) {
            if(!isNaN(value)){
                if(formatter == "1") { // 添加百分号
                    value = value.toFixed(2);
                    return value + "%";
                } else if(formatter == "2") {  // 乘以100后添加百分号
                    var percentValue = value * 100;
                    percentValue = percentValue.toFixed(2);
                    percentValue = percentValue + "%";
                    return percentValue;
                } else if(formatter.indexOf("#") != -1) {
                    if(value != null) {
                        var result = (value.toString()).indexOf(".");
                        if(result != -1) {
                            var fixNumber = formatter.length;
                            value = value.toFixed(fixNumber);
                        }
                        return value;
                    }
                } else if(formatter.indexOf("0.") != -1) {
                    if(value != null) {
                        var baseNumber = parseFloat(formatter);
                        var result = value * baseNumber;
                        result = result.toFixed(2);
                        return result;
                    }
                }
            }
        }

        //动态数字格式化
        function dynamicNumberFormat(formatter, value, row, index) {
            if(!isNaN(value)){
                var formatType = $("#" + formatter).val();
                if(formatType == "1") { // 添加百分号
                    value = value.toFixed(2);
                    return value + "%";
                } else if(formatType == "2") {  // 乘以100后添加百分号
                    var percentValue = value * 100;
                    percentValue = percentValue.toFixed(2);
                    percentValue = percentValue + "%";
                    return percentValue;
                } else if(formatType.indexOf("#") != -1) {
                    if(value != null) {
                        var result = (value.toString()).indexOf(".");
                        if(result != -1) {
                            var fixNumber = formatType.length;
                            value = value.toFixed(fixNumber);
                        }
                        return value;
                    }
                } else if(formatType.indexOf("0.") != -1) {
                    if(value != null) {
                        var baseNumber = parseFloat(formatType);
                        var result = value * baseNumber;
                        result = result.toFixed(2);
                        return result;
                    }
                }
            }
        }

        // 转义(将编码转为名称)
        function transInfo(field, value, row, index) {
            var text = "";
            $("#" + field + " option").each(function(){  //遍历所有option
                var opt = $(this).val();   //获取option值
                var optTxt = $(this).text();
                if(value == opt) {
                    text = optTxt;
                    return;
                }
            });

            return text;
        }

        function openNewWin() {
            var monthCode = $('#monthCode').val();
            var custCode = $("#custCode").val();
            var orgCodes = $("#hid_treeNode").val();
            var orgNames = $("#treeNodeId").val();
            orgNames = encodeURI(encodeURI(orgNames));
            var rcvProvCode = $("#hid_rcvProvCode").val();
            var rcvProvNames = $("#rcvProvCodeId").val();
            rcvProvNames = encodeURI(encodeURI(rcvProvNames));
            window.open("${pageContext.request.contextPath}/rest/auts/flightRcv/index?monthCode=" + monthCode + "&custCode=" + custCode + "&orgCodes=" + orgCodes + "&orgNames=" + orgNames + "&rcvProvCode=" + rcvProvCode + "&rcvProvNames=" + rcvProvNames);
        }

        // 树形数据
        var treeWinDig;
        function selectMyOrgTree(rptId,attrName,paramKey,parentParamKey){
            var paramValue = $("#" + paramKey).val();
            var parentValue = $("#" + parentParamKey).val();
            var url = basePath + "/rptTools/treeData/tree/" + attrName + "/" + rptId + "/" + paramValue + "/" + parentValue;
            /*var url = "";
            if(paramValue != '') {
                url = basePath + "/rptTools/treeData/tree/" + attrName + "/" + rptId + "/" + paramValue;
            } else {
                url = basePath + "/rptTools/treeData/tree/" + attrName + "/" + rptId;
            }*/
            treeWinDig = popWinOpenAjaxFrame(rptId,'选择',url,650,450);
        }

        function treeDataBack(key1,key2,value1,value2) {
            if(value2 != null && value2 != ''){
                value2 = "'" + value2.replace(new RegExp(',','gm'),"','") + "'";
            }
            $("#"+key1).val(value1);
            $("#"+key2).val(value2);
            treeWinDig.close();
        }
    </script>
</body>
</html>